package com.madrivergroup.mamatodo.tasks;
import java.io.Serializable;
import java.util.Date;

public class Task implements Serializable {
	
	private static final long serialVersionUID = 7663799994L;
	
	private long     id       = 0;
	private boolean complete  = false;
	private String  name      = null;
	private Date   createDate = null;
	public Task(String n) {
		setName( n );
	}
	
	public void setId( long i ) {
		id = i;
	}
	public long getId() {
		return id;
	}
	
	public void setName( String n ) {
		name = n;
	}
	public String getName() {
		return name;
	}
	
	public boolean isComplete() {
		return complete;
	}

	public void setComplete(boolean complete) {
		this.complete = complete;
	}

	public void toggleTask() {
		complete = !complete;
		
	}
	public void setCreateDate( Date d) {
		createDate = d;
	}
	public Date getCreateDate() {
		return createDate;
	}
	
	
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj ) {
		
		if( this == obj ) {
			return true;
		}
		if( obj == null ) {
			return false;
		}
		if( getClass() != obj.getClass() ) {
			return false;
		}
		
		Task task = (Task)obj;
		if( id != task.id ) return false;
		if( name       != null ? !name.equals( task.name ) : (task.name != null) ) return false; 
		if( createDate != null ? !createDate.equals( task.createDate ) : (task.createDate != null) ) return false; 
		if( complete   != task.complete) return false; 

		
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		int hashCode = (null != name) ? name.hashCode() : 0;
		hashCode += id;
		
		return hashCode;
	}
	
	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("Task [id=" + id + " name=" + name + " , complete=" + complete + " , createDate=" + createDate + " ]" );
		
		return buf.toString();
	}


}
